package LeetCode;

public class LC_538_ConvertBSTtoGreaterTree {

    public static void main(String[] args) {

    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public class Solution {
        private int sum = 0;

        void post(TreeNode current) {
            if (current != null) {
                post(current.right);
                current.val += sum;
                sum = current.val;
                post(current.left);
            }
        }

        public TreeNode convertBST(TreeNode root) {
            post(root);
            return root;
        }

    }


}